﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace HelloWPF.DependencyAttachedProperty.DependencyAttachedProperty
{
    /// <summary>
    /// 继承DependencyObject(依赖对象)
    /// 附加属性的包装器与依赖属性不同
    /// 依赖属性使用CLR属性对GetValue和SetValue两个方法进行包装
    /// 附加属性则使用两个方法分别进行包装
    /// 附加属性
    /// </summary>
    public class School: DependencyObject
    {
        /// <summary>
        /// 得到年级
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static int GetGrade(DependencyObject obj)
        {
            return (int)obj.GetValue(GradeProperty);
        }

        /// <summary>
        /// 设置年级
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="value"></param>
        public static void SetGrade(DependencyObject obj, int value)
        {
            obj.SetValue(GradeProperty, value);
        }

        /// <summary>
        /// 约定俗称以Property结尾
        /// </summary>
        public static readonly DependencyProperty GradeProperty =
            DependencyProperty.RegisterAttached("Grade", typeof(int), typeof(School), new PropertyMetadata(0));
    }
}
